package hermesV3.protocols;

import hermesV3.agent.AbstractProtocol;
import hermesV3.agent.Interaction;

/**
 * This Protocol manages the communication in the opening of the simulation,
 * previously the collision detection start.
 * 
 * @see it.unicam.cs.cosy.bioshape.core.components.GlobalCoordinator
 * @see it.unicam.cs.cosy.bioshape.core.components.LocalCoordinator
 * @see hermesV3.services.Space.SpaceManager
 * 
 * @author Federico Buti, Gaston Alanis, Matteo Micheletti, Andrea Piermarteri
 */
public class SplitSpaceProtocol extends AbstractProtocol {

	/** Auto-generated serial ID */
	private static final long serialVersionUID = 5338161764057772696L;

	/**
	 * {@code Interaction} to send the {@code List} of {@code LocalCoordinator}s
	 * {@code Identificator}s.
	 */
	public static final String INTERACTIONSENDIDS = "SendId";
	/** {@code Interaction} sent by the {@code SpaceManager} once set up is over. */
	public static final String INTERACTIONDIVISIONDONE = "DivisionDone";
	/**
	 * {@code Interaction} to send simulation info to the
	 * {@code LocalCoordinator}s.
	 */
	public static final String INTERACTIONSENDLOCALSDATA = "SendLocalsData";
	/** {@code Interaction} to sent {@code Bounds} to {@code LocalCoordinator}s. */
	public static final String INTERACTIONSENDBOUNDS = "SendBounds";
	/**
	 * {@code Interaction} to sent {@code WallEntity} objects to
	 * {@code LocalCoordinator}s.
	 */
	public static final String INTERACTIONSENDWALLS = "SendWalls";
	/** Response {@code Interaction} to eventual errors */
	public static final String INTERACTIONERROR = "Error";

	/** Declares {@code Interaction}s among {@link SplitSpaceProtocol} actions. */
	public SplitSpaceProtocol() {
		super("SplitSpaceProtocol");

		String[] parameterNameSendId = new String[1];
		parameterNameSendId[0] = "SendId";
		Class<?>[] parameterTypeSendId = new Class[1];
		parameterTypeSendId[0] = java.util.ArrayList.class;
		Interaction sendId = new Interaction(INTERACTIONSENDIDS,
				INTERACTIONSENDIDS, INTERACTIONSENDIDS, parameterNameSendId,
				parameterTypeSendId);
		addInteraction(sendId);

		String[] parameterNameDivisionDone = new String[0]; // no params
		Class<?>[] parameterTypeDivisionDone = new Class[0]; // no params
		Interaction divisionDone = new Interaction(INTERACTIONDIVISIONDONE,
				INTERACTIONDIVISIONDONE, INTERACTIONDIVISIONDONE,
				parameterNameDivisionDone, parameterTypeDivisionDone);
		addInteraction(divisionDone);

		String[] parameterNameSendLocalsData = new String[1];
		parameterNameSendLocalsData[0] = "SendLocalsData";
		Class<?>[] parameterTypeSendLocalsData = new Class[1];
		parameterTypeSendLocalsData[0] = Object.class;
		Interaction sendLocalsData = new Interaction(INTERACTIONSENDLOCALSDATA,
				INTERACTIONSENDLOCALSDATA, INTERACTIONSENDLOCALSDATA,
				parameterNameSendLocalsData, parameterTypeSendLocalsData);
		addInteraction(sendLocalsData);

		String[] parameterNameSendWalls = new String[1];
		parameterNameSendWalls[0] = "SendWalls";
		Class<?>[] parameterTypeSendWalls = new Class[1];
		parameterTypeSendWalls[0] = java.util.ArrayList.class;
		Interaction sendWalls = new Interaction(INTERACTIONSENDWALLS,
				INTERACTIONSENDWALLS, INTERACTIONSENDWALLS,
				parameterNameSendWalls, parameterTypeSendWalls);
		addInteraction(sendWalls);

		String[] parameterNameError = new String[1];
		parameterNameError[0] = "Error";
		Class<?>[] parameterTypeError = new Class[1];
		parameterTypeError[0] = String.class;
		Interaction error = new Interaction(INTERACTIONERROR, INTERACTIONERROR,
				INTERACTIONERROR, parameterNameError, parameterTypeError);
		addInteraction(error);

		addErrorLink(sendId, error);
		addErrorLink(divisionDone, error);
		addErrorLink(sendLocalsData, error);
		addErrorLink(sendWalls, error);
	}
}